package com.sl.springboot.controller;


import cn.hutool.core.util.StrUtil;
import com.sl.springboot.common.Result;
import com.sl.springboot.entity.User;
import com.sl.springboot.service.UserService;
import com.sl.springboot.service.impl.UserServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.rmi.ServerException;


@RestController
@RequiredArgsConstructor
@CrossOrigin
public class WebController {

    private final UserService userService;

    @PostMapping("/login")
    public Result login(@RequestBody User user) throws Exception {
        if(StrUtil.isBlank(user.getUsername()) || StrUtil.isBlank(user.getPassword())){
            return Result.error("数据输入不合法");
        }
        User currentUser = userService.login(user);
        return Result.success(currentUser);
    }



}